package com.whitelist;

import java.io.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class SwitchWhiteList {
    public static void main(String[] args) throws IOException {
        String filepath="src/com/whitelist/1.json";
        BufferedReader reader = new BufferedReader(new FileReader(filepath));
        String line = reader.readLine();
        String regex = "name\":\"(?<name>\\w+\\b)\",\"uuid\":\"(?<uuid>\\w+-\\w+-\\w+-\\w+-\\w+)";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(line);
        Writer writer;
        writer = new BufferedWriter(new FileWriter("src/com/whitelist/whitelist.json"));
        writer.write("[\n");
        while(matcher.find()){
            writer.write(
                    "  {\n"
                    +
                    "    \"uuid\": \""
                    +
                    matcher.group("uuid")
                    +
                    "\",\n"
                    +
                    "    \"name\": \""
                    +
                    matcher.group("name")
                    +
                    "\"\n"
                    +
                    "  },\n"
                    );
//            System.out.println(matcher.group("name")+"@@@@"+matcher.group("uuid"));
        }
        writer.write("]");
        writer.close();
        System.out.println("已写入");
    }
}
